<!DOCTYPE html>
<html lang="en">
<head>
    <base href="<%=basePath%>">

    <title>合同列表</title>

    <meta name="pragma" content="no-cache">
    <meta name="cache-control" content="no-cache">
    <meta name="expires" content="0">
    <link href="/static/easyui/themes/insdep/easyui.css" rel="stylesheet" type="text/css">
    <link href="/static/easyui/themes/insdep/easyui_animation.css" rel="stylesheet" type="text/css">
    <link href="/static/easyui/themes/insdep/easyui_plus.css" rel="stylesheet" type="text/css">
    <link href="/static/easyui/themes/insdep/insdep_theme_default.css" rel="stylesheet" type="text/css">
    <link href="/static/easyui/themes/insdep/icon.css" rel="stylesheet" type="text/css">
    <link href="/static/easyui/themes/color.css" rel="stylesheet" type="text/css">

    <link href="/static/ztree/zTreeStyle/zTreeStyle.css" rel="stylesheet" type="text/css">
    <link href="/static/css/common.css" rel="stylesheet" type="text/css">

    <script type="text/javascript" src="/static/jquery/jquery.min.js"></script>
    <script type="text/javascript" src="/static/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/static/easyui/themes/insdep/jquery.insdep-extend.min.js"></script>
    <script type="text/javascript" src="/static/ztree/jquery.ztree.all.min.js"></script>
    <script type="text/javascript" src="/static/easyui/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="/static/kindeditor/kindeditor-all-min.js"></script>

</head>
<body>
<div>
    <form action="/searchContract" method="post">
        <select name="filter" class="easyui-combobox theme-textbox-radius" style="width:120px" id="contractOne">
            <option value="customer">客户</option>
            <option value="contact">联系人</option>
            <option value="principal">负责人</option>
        </select>
        <select name="likeOrAccurate" ,class="easyui-combobox theme-textbox-radius" style="width:100px"
                id="contractTwo">
            <option value="like">包含字段</option>
            <option value="accurate">精确查询</option>
        </select>
        <span>请输入关键字:</span>
        <input name="search" id="contract" style="line-height:26px;border:1px solid #ccc">
        <!--<a href="javascript:void(0);" class="easyui-linkbutton" plain="true" onclick="doSearch()"
           data-options="iconCls:'icon-search',plain:true">搜索</a>-->
        <input class="easyui-linkbutton" plain="true" data-options="iconCls:'icon-search',plain:true" type="submit"
               value="搜索">
    </form>
</div>

<table id="contractList" class="easyui-datagrid"></table>
<div id="toolbar">
    <a href="javascript:void(0);" onclick="return add('toAddContract')"
       class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true">新建</a>
    <a href="javascript:void(0);" onclick="return del('deleteContract')"
       class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true">删除</a>
    <a href="javascript:void(0);" onclick="return edit('toEditContract');" id="editBtn"
       class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true">修改</a>
</div>
</div>
<script type="text/javascript">
    //条件查询
    function doSearch() {
        $('#contractList').datagrid('load', {
            "contractName": $('#contract').val(),
            "contractOne": $("#contractOne").val(),
            "contractTwo": $("#contractTwo").val()
        });
    }

    //添加合同
    function add(url) {
        parent.parent.openTopWindow({
            width: 800,
            height: 600,
            title: "添加合同",
            "url": url,
            close: function () {
                $("#positionList").datagrid("reload");
            }

        });
    }

    //修改部门
    function edit(url) {
        var rows = $("#contractList").datagrid("getChecked");
        if (!rows.length) {
            $.messager.alert("警告", "请选择要修改的数据");
            return false;
        }
        var id = rows[0].id;
        parent.parent.openTopWindow({
            width: 800,
            height: 600,
            title: "修改岗位信息",
            "url": url + "?id=" + id,
            close: function () {
                $("#contractList").datagrid("reload");
            }

        });
    }

    //查看
    function see() {
        var rows = $("#contractList").datagrid("getChecked");
        var id = rows[0].id;
        parent.parent.openTopWindow({
            width: 800,
            height: 600,
            title: "查看岗位信息",
            "url": "seeContract?id=" + id,
            close: function () {
                $("#contractList").datagrid("reload");
            }

        });
    }


    //删除部门
    function del(url) {
        //获取到选中的一行数据
        var rows = $("#contractList").datagrid("getChecked");
        if (!rows.length) {
            $.messager.alert("警告", "请选择要删除的数据");
            return;
        }

        $.messager.confirm("警告", "数据删除后无法恢复，是否确认删除", function (b) {
            if (b) {
                var ids = new Array();
                $.each(rows, function (index, obj) {
                    ids.push(obj.id);
                });
                //将数组中元素使用,分割拼接为一个字符串
                ids = ids.join(",");
                $.post(url,
                    {
                        "ids": ids
                    },
                    function (data) {
                        if (data && data.success) {
                            $.messager.alert("提示", data.message);
                            $("#contractList").datagrid("reload");
                            return;
                        }
                        $.messager.alert("警告", data.message);
                    }, "json");
            }
        });
    }

    //加载用户数据
    $(function () {
        $("#contractList").datagrid({
            url: "/getContract",
            pagination: true,
            toolbar: "#toolbar",
            fitColumns: true,
            idField: "contractid",
            rownumbers: true,
            singleSelect: true,
            showHeader: true,//定义是否显示头部
            columns: [
                [
                    {field: "id", title: "选择合同", checkbox: true},
                    {field: "number", title: "合同编号"},
                    {
                        field: "custName", title: "客户",
                        formatter: function (value, rowData, index) {
                            return rowData.tbCrmCustomer.name;
                        }
                    },
                    {
                        field: "userName", title: "负责人",
                        formatter: function (value, rowData, index) {
                            return rowData.tbSystemUser.username;
                        }
                    },//ownerUserName
                    {
                        field: "csname", title: "联系人",
                        formatter: function (value, rowData, index) {
                            return rowData.tbCrmContacts.csname;
                        }
                    },
                    {field: "dueTime", title: "签约日期"},
                    {field: "price", title: "合同金额"},
                    {field: "status", title: "状态"},
                    {field: "endTime", title: "距离到期时间"},
                    {
                        field: "operation", title: "操作", formatter: function (value, row, index) {
                            return "<a href='javascript:void(0)' onclick='return see(" + index + ")'>查看</a>" /*+
                                "&nbsp;&nbsp<a href='javascript:void(0)' onclick='return modify(" + index + ")'>编辑</a>"*/;
                        }
                    }


                ]
            ],
            loadFilter: function (data) {
                //data是服务器返回的数据,将服务器端返回的数据转换为datagrid需要的格式
                return {"total": data.total, "rows": data.rows};
            }

        });
    });
</script>
</body>
</html>